<?php
/* $Id: announce.php,v 1.5 2003/10/08 07:12:32 tuxmonkey Exp $ */
/**
 * @package Issue-Tracker
 * @subpackage Announcements
 */

if (strpos($_SERVER['PHP_SELF'],basename(__FILE__)) !== false) {
  print "Direct module access forbidden.";exit;}
  
if (permission_check("create_announcements")) {
    $links[] = array(
        "txt" => " New Announcement ",
        "url"   => "?module=announce&action=new",
    "img" => $_ENV['imgs']['new_announce']
    );
}

    $sql  = "SELECT a.aid,a.title,a.posted,u.username ";
    $sql .= "FROM announcements a,users u ";
    $sql .= "WHERE a.is_global='t'";
    $sql .= "AND u.userid=a.userid ";
    $sql .= "ORDER BY a.posted DESC";
    $s = $dbi->fetch_all($sql,"array");
  $systems = $s;

//$system = announcements();
$smarty->assign('systems',$systems);
foreach ($_SESSION['groups'] as $gid) 
{
  $sql  = "SELECT aid ";
  $sql .= "FROM announce_permissions ";
  $sql .= "WHERE gid='$gid'";
  $a = $dbi->fetch_all($sql,'uni');
  if (!empty($a))
  {
    $sql  = "SELECT a.aid,a.title,a.posted,u.username ";
    $sql .= "FROM announcements a,users u ";
    $sql .= "WHERE a.aid IN ($a) ";
    $sql .= "AND u.userid=a.userid ";
    $sql .= "ORDER BY a.posted DESC";
    $a = $dbi->fetch_all($sql,"array");
  }
  $announcements[$gid] = $a;
}
$smarty->assign('announcements',$announcements);
$smarty->display("announce/announce.tpl");
?>